package top.haichi.webpaper.Interceptors;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;
import top.haichi.webpaper.entity.Result;
import top.haichi.webpaper.utils.InterceptorUtils;
import top.haichi.webpaper.utils.JwtUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
@Slf4j
/**
 * 登录拦截器
 */
public class UserLoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
            if(JwtUtils.getTokenParam(request,"id")==null){
                InterceptorUtils.result(Result.tokenError(),response);
                return false;
            }
            return true;
    }
}
